<div class="col-lg-12">
    <div>
        <div class="card col-md-12">
            <div class="card-header">
                <h4 style="font-size: 20px">商品上传</h4>
            </div>
            <div class="card-body">
                <div>
                    <div class="form-group">
                        <label for="title-input">商品标题</label>
                        <input class="form-control" id="title-input"
                               placeholder="请输入商品标题..">
                    </div>
                    <div class="form-group">
                        <label for="price-input">商品价格</label>
                        <input class="form-control" id="price-input"
                               placeholder="请输入商品价格..">
                    </div>
                    <div class="form-group">
                        <label class=for="example-file-input">上传商品图片</label>
                        <div>
                            <input type="file" id="file-input" accept="image/*">
                        </div>
                    </div>
                    <div class="form-group" id="display-picture">

                    </div>
                    <div class="form-group text-center">
                        <button class="btn btn-primary" id="upload_product_button">确认添加商品</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $("#upload_product_button").on("click", function () {
        var formData = new FormData();
        var file = document.getElementById("file-input").files[0];
        if (file === undefined) {
            alert("请上传文件");
            return;
        }
        formData.append("picture", file);
        var price = document.getElementById("price-input").value;
        formData.append("price", price);
        var title = document.getElementById("title-input").value;
        formData.append("title", title);
        var token = localStorage.getItem("token");
        formData.append("token", token);
        if (product_seller_upload(formData)) {
            $("main").load("element/product-list.html");
        }
    })
</script>